﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ElingOA6_Admin_DSJCJ.BLL
{
    /// <summary>
    /// 
    /// </summary>
    public class PeerReview
    {
        /// <summary>
        /// Dal定义的便利
        /// </summary>
        private readonly DAL.PeerReview dal = new DAL.PeerReview();

        /// <summary>
        /// 是否开启
        /// </summary>
        /// <returns>数据列表</returns>
        public DataSet GetIsFtatus()
        {
            return dal.GetIsFtatus();
        }

        /// <summary>
        /// 开始设定
        /// </summary>
        /// <param name="model">主题Model</param>
        /// <param name="peerReviewID">主题主键ID</param>
        /// <returns>是否开始</returns>
        public bool Satrt(ElingOA6_Admin_DSJCJ.Model.PeerReview model, decimal peerReviewID)
        {
            return dal.Satrt(model, peerReviewID);
        }

        /// <summary>
        /// 结束设定
        /// </summary>
        /// <param name="model">主题Model</param>
        /// <param name="peerReviewID">主题主键ID</param>
        /// <returns>是否结束</returns>
        public bool End(ElingOA6_Admin_DSJCJ.Model.PeerReview model, decimal peerReviewID)
        {
            return dal.End(model, peerReviewID);
        }

        /// <summary>
        /// 得到主题的主题和编号
        /// </summary>
        /// <returns>数据列表</returns>
        public List<Model.PeerReview> GetList()
        {
            DataSet ds = dal.GetList();
            return DataTableToList(ds.Tables[0]);
        }


        /// <summary>
        ///  获得数据列表
        /// <summary>
        /// <creator>chenly</creator>
        /// <date>2013-10-18</date>
        /// </summary>
        /// <param name="dt">一张DataTable</param>
        /// <returns>返回Model</returns>
        public List<Model.PeerReview> DataTableToList(DataTable dt)
        {
            List<Model.PeerReview> modelList = new List<Model.PeerReview>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.PeerReview model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.PeerReview();
                    if (dt.Rows[n]["FPeerReviewID"] != null && dt.Rows[n]["FPeerReviewID"].ToString() != "")
                    {
                        model.FPeerReviewID = decimal.Parse(dt.Rows[n]["FPeerReviewID"].ToString());
                    }
                    if (dt.Rows[n]["FTitle"] != null)
                    {
                        model.FTitle = dt.Rows[n]["FTitle"].ToString();
                    }
                    if (dt.Rows[n]["FStatus"] != null)
                    {
                        model.FStatus = dt.Rows[n]["FStatus"].ToString();
                    }
                    if (dt.Rows[n]["FBeginDate"] != null && dt.Rows[n]["FBeginDate"].ToString() != "")
                    {
                        model.FBeginDate = DateTime.Parse(dt.Rows[n]["FBeginDate"].ToString());
                    }
                    if (dt.Rows[n]["FEndDate"] != null && dt.Rows[n]["FEndDate"].ToString() != "")
                    {
                        model.FEndDate = DateTime.Parse(dt.Rows[n]["FEndDate"].ToString());
                    }
                    if (dt.Rows[n]["FIsVoteIPControl"] != null && dt.Rows[n]["FIsVoteIPControl"].ToString() != "")
                    {
                        model.FIsVoteIPControl = dt.Rows[n]["FIsVoteIPControl"].ToString();
                    }
                    if (dt.Rows[n]["FIsLookIPControl"] != null && dt.Rows[n]["FIsLookIPControl"].ToString() != "")
                    {
                        model.FIsLookIPControl = dt.Rows[n]["FIsLookIPControl"].ToString();
                    }
                    if (dt.Rows[n]["FIsSelectAll"] != null && dt.Rows[n]["FIsSelectAll"].ToString() != "")
                    {
                        model.FIsSelectAll = dt.Rows[n]["FIsSelectAll"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        /// <param name="model">主表Model</param>
        /// <param name="peerReviewIPList">IP集合</param>
        /// <param name="peerReviewRuleOptionList">选项集合</param>
        /// <param name="peerReviewRuleList">细则集合（包括得分的选项）</param>
        public void Add(ElingOA6_Admin_DSJCJ.Model.PeerReview model, List<Model.PeerReviewIP> peerReviewIPList, List<Model.PeerReviewRuleOption> peerReviewRuleOptionList, List<Model.PeerReviewRule> peerReviewRuleList)
        {
            dal.Add(model, peerReviewIPList, peerReviewRuleOptionList, peerReviewRuleList);
		}
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="model">主表Model</param>
        /// <param name="peerReviewIPList">IP集合</param>
        /// <param name="peerReviewRuleOptionList">选项集合</param>
        /// <param name="peerReviewRuleList">细则集合（包括得分的选项）</param>
        public void Update(ElingOA6_Admin_DSJCJ.Model.PeerReview model, List<Model.PeerReviewIP> peerReviewIPList, List<Model.PeerReviewRuleOption> peerReviewRuleOptionList, List<Model.PeerReviewRule> peerReviewRuleList)
        {
            dal.Update(model, peerReviewIPList, peerReviewRuleOptionList, peerReviewRuleList);
        }
        /// <summary>
        /// 有评议结果是的更新方法
        /// </summary>
        /// <param name="model">主表的model</param>
        /// <param name="peerReviewIPList">IP集合</param>
        /// <param name="peerReviewRuleOptionList">选项集合</param>
        public void UpdateTwoList(ElingOA6_Admin_DSJCJ.Model.PeerReview model, List<Model.PeerReviewIP> peerReviewIPList, List<Model.PeerReviewRuleOption> peerReviewRuleOptionList)
        {
            dal.UpdateTwoList(model, peerReviewIPList, peerReviewRuleOptionList);
        }
    }
}
